package com.example.springboot.service.impl;

import com.example.springboot.dto.EmailReqDTO;
import com.example.springboot.service.EmailService;
import com.example.springboot.utils.MailUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Service;

import javax.mail.*;
import java.util.logging.Logger;

@Service
public class EmailServiceImpl implements EmailService {
    private static final Logger logger = Logger.getLogger(EmailServiceImpl.class.getName());
    // 发件人称号，同邮箱地址
    @Value("${email.user}")
    private String user;
    // 如果是qq邮箱可以使户端授权码，或者登录密码
    @Value("${email.code}")
    private  String code;
    //发件人邮箱对应的服务器域名，163邮箱：smtp.163.com qq邮箱：smtp.qq.com
    @Value("${email.host}")
    private  String host;
    @Value("${email.auth}")
    private  String auth;

    @Override
    public void sendEmail(EmailReqDTO emailReqDTO)  {
        boolean sendMail = MailUtils.sendMail(emailReqDTO.getTo(), emailReqDTO.getMsg(), emailReqDTO.getTitle(), user, code, auth, host);
        if (sendMail){
            logger.info("发送成功！");
        }
    }
}
